package com.wsoft.system.service.impl;

import cn.hutool.core.convert.Convert;
import com.wsoft.constant.RedisKeyConstant;
import com.wsoft.core.annotation.GetRedisCache;
import com.wsoft.core.annotation.InitRedisCache;
import com.wsoft.system.dto.TsConfigDto;
import com.wsoft.system.entity.TsConfigEntity;
import com.wsoft.system.mapper.TsConfigMapper;
import com.wsoft.system.service.ITsConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统配置表 服务实现类
 * </p>
 *
 * @author kyle
 * @since 2024年09月01日 08:51:54
 */
@Service
public class TsConfigServiceImpl extends ServiceImpl<TsConfigMapper, TsConfigEntity> implements ITsConfigService {

    @Override
    public boolean insert(TsConfigDto dto) {
        TsConfigEntity entity = Convert.convert(TsConfigEntity.class, dto);
        return save(entity);
    }

    @Override
    @InitRedisCache(type = RedisKeyConstant.CONFIG_CACHE_ALL,
                    value = RedisKeyConstant.REDIS_NULL)
    public boolean update(TsConfigDto dto) {
        TsConfigEntity entity = Convert.convert(TsConfigEntity.class, dto);
        return updateById(entity);
    }

    @Override
    public boolean delete(Long id) {
        return removeById(id);
    }

    @Override
    public TsConfigEntity getConfig(Long id) {
        return getById(id);
    }

    @Override
    @GetRedisCache( type = RedisKeyConstant.CONFIG_CACHE_ALL,
            value = RedisKeyConstant.REDIS_NULL)
    public List<TsConfigEntity> listConfig() {
        return list();
    }

}
